home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / pluginy Firefox / 2207 / 2207.xpi / chrome / cooliris.jar / content / cooliris / coolirisHighlightManager.js < prev    next >
Text File  |  2010-01-28  |  7KB  |  237 lines

  1. var cpvw_highlightManager={contextIconTimer:null,parentDoc:null,isShowingIcon:false,selectedText:"",posX:null,posY:null,iconHoverTimer:null,iconHoverInterval:500,hideMenuTimer:null,isShowingMenu:false,contextIcon:null,handleEvent:function(_1){
  2. var _2=cpvw_prefHandler.getPref(cpvw_Prefs.prefInlineSubsearch);
  3. if(!_2){
  4. return;
  5. }
  6. if(_1.type=="mouseup"){
  7. if(this.parentDoc&&cpvw_get("cpvw_contextIcon",this.parentDoc)){
  8. cpvw_get("cpvw_contextIcon",this.parentDoc).parentNode.removeChild(cpvw_get("cpvw_contextIcon",this.parentDoc));
  9. }
  10. if(this.getSelection()!=""){
  11. this.getSelectionPosition();
  12. var _3=this;
  13. setTimeout(function(){
  14. _3.showIcon(_1);
  15. },500);
  16. }
  17. }
  18. },getSelectionPosition:function(){
  19. var _4=document.commandDispatcher.focusedWindow;
  20. var _5=_4.getSelection();
  21. var _6=this.parentDoc.createElement("cpvw");
  22. _6.setAttribute("id","cpvw_temporaryElement");
  23. _6.innerHTML="a";
  24. var _7=_5.getRangeAt(0);
  25. var _8=_7.endContainer;
  26. var _9=_7.endOffset;
  27. var _a=_7.startContainer;
  28. var _b=_7.startOffset;
  29. var _c=_7.startContainer.parentNode;
  30. var _d=this.parentDoc;
  31. if(_c&&_c.localName.toLowerCase()=="tbody"||_c.localName.toLowerCase()=="tr"||_c.localName.toLowerCase()=="table"){
  32. return;
  33. }
  34. var _e=_d.createRange();
  35. if(_7.comparePoint(_7.startContainer,_7.startOffset+1)==0){
  36. try{
  37. _e.setStart(_7.startContainer,_7.startOffset+1);
  38. }
  39. catch(ex){
  40. var _f=this.findNextTextNode(_d,_7.commonAncestorContainer,_7.startContainer);
  41. _e.setStart(_f,1);
  42. _c=_f.parentNode;
  43. _a=_f;
  44. _b=0;
  45. }
  46. _e.insertNode(_6);
  47. this.getPos(_6);
  48. }else{
  49. _e.setStart(_7.startContainer,_7.startOffset);
  50. _e.insertNode(_6);
  51. this.getPos(_6);
  52. }
  53. _e.deleteContents();
  54. if(cpvw_get("cpvw_temporaryElement",_d)&&cpvw_get("cpvw_temporaryElement",_d).parentNode){
  55. _c=cpvw_get("cpvw_temporaryElement",_d).parentNode;
  56. cpvw_get("cpvw_temporaryElement",_d).parentNode.removeChild(cpvw_get("cpvw_temporaryElement",_d));
  57. _c.normalize();
  58. }
  59. var _10=_d.createRange();
  60. _10.setStart(_a,_b);
  61. _10.setEnd(_8,_9);
  62. _5.removeAllRanges();
  63. _5.addRange(_10);
  64. },getPos:function(_11){
  65. this.posX=_11.offsetLeft;
  66. this.posY=_11.offsetTop;
  67. if(_11.offsetParent){
  68. var _12=_11;
  69. while(_12.offsetParent){
  70. this.posX+=_12.offsetParent.offsetLeft;
  71. this.posY+=_12.offsetParent.offsetTop;
  72. _12=_12.offsetParent;
  73. }
  74. }
  75. },getSelection:function(){
  76. var _13=document.commandDispatcher.focusedWindow;
  77. this.parentDoc=_13.document;
  78. var _14=_13.getSelection();
  79. var _15=cpvw_jsUtils.trimWhitespace(_14.toString());
  80. this.selectedText=_15;
  81. return _15;
  82. },clearTimer:function(){
  83. clearTimeout(this.contextIconTimer);
  84. this.contextIconTimer=null;
  85. },showIcon:function(evt){
  86. var _17=this;
  87. this.removeIcon();
  88. var _18=this.parentDoc.createElement("img");
  89. _18.setAttribute("src","chrome://cooliris/skin/new/mouseover.png");
  90. _18.setAttribute("id","cpvw_contextIcon");
  91. _18.setAttribute("title","Click on the icon to see the options");
  92. _18.setAttribute("style","z-index:2147483647;border: 0px solid blue;-moz-opacity:0.20;position:absolute;width:20px;height:20px;margin-top:-20px");
  93. _17.contextIcon=_18;
  94. var _19=function(){
  95. _18.style.opacity=parseFloat(_18.style.opacity)+0.2;
  96. if(parseFloat(_18.style.opacity)<0.9){
  97. setTimeout(_19,75);
  98. }
  99. };
  100. setTimeout(_19,50);
  101. var py=this.posY-21;
  102. if(this.posY-21<0){
  103. _18.style.marginTop="0px";
  104. }
  105. _18.style.left=(this.posX-10)+"px";
  106. _18.style.top=this.posY+"px";
  107. this.parentDoc.body.appendChild(_18);
  108. this.isShowingIcon=true;
  109. this.clearTimer();
  110. _18.addEventListener("mouseover",function(evt){
  111. cpvw_get("cooliris_rightclick").openPopup(_18,"overlap",20,20,false,false);
  112. },true);
  113. _18.addEventListener("click",function(evt){
  114. cpvw_get("cooliris_rightclick").openPopup(_18,"overlap",20,20,false,false);
  115. },true);
  116. _18.addEventListener("mouseout",function(evt){
  117. clearTimeout(_17.iconHoverTimer);
  118. },true);
  119. this.contextIconTimer=setTimeout(function(){
  120. _17.removeIcon();
  121. },5000);
  122. },initHideMenu:function(){
  123. var _1e=this;
  124. this.hideMenuTimer=setTimeout(function(){
  125. cpvw_get("cooliris_rightclick").hidePopup();
  126. _1e.hideMenuTimer=null;
  127. _1e.isShowingMenu=false;
  128. },1500);
  129. },initShowMenu:function(){
  130. if(this.hideMenuTimer){
  131. clearTimeout(this.hideMenuTimer);
  132. this.hideMenuTimer=null;
  133. }
  134. },setContextMenuItems:function(){
  135. while(cpvw_get("cooliris_rightclick").childNodes.length>0){
  136. cpvw_get("cooliris_rightclick").removeChild(cpvw_get("cooliris_rightclick").firstChild);
  137. }
  138. var _1f=cpvw_prefHandler.getPref(cpvw_Prefs.prefCMenuItems);
  139. var _20=_1f.split(",");
  140. if(cpvw_contextSitesTreeView.arrCMenuItems==null){
  141. cpvw_contextSitesTreeView.loadContextSites();
  142. }
  143. var str="";
  144. for(var key in cpvw_contextSitesTreeView.arrCMenuItems){
  145. str+=key+", ";
  146. }
  147. cpvw_objContextMenu.parentDoc=this.parentDoc;
  148. cpvw_objContextMenu.selectStr=this.selectedText;
  149. var _23=this;
  150. for(var i=0;i<_20.length;i++){
  151. if(cpvw_contextSitesTreeView.arrCMenuItems[_20[i]]!=null){
  152. var _25=document.createElement("menuitem");
  153. _25.setAttribute("label",cpvw_contextSitesTreeView.arrCMenuItems[_20[i]].label);
  154. _25.setAttribute("image",cpvw_contextSitesTreeView.arrCMenuItems[_20[i]].image);
  155. _25.setAttribute("value",i);
  156. _25.setAttribute("class","menuitem-iconic");
  157. _25.addEventListener("command",function(evt){
  158. _23.isShowingMenu=true;
  159. cpvw_objContextMenu.initPreviewShow(this,"click",evt);
  160. },false);
  161. _25.addEventListener("mouseover",function(evt){
  162. cpvw_objContextMenu.initPreviewShow(this);
  163. },false);
  164. _25.addEventListener("mouseout",function(evt){
  165. cpvw_objContextMenu.initPreviewHide();
  166. },false);
  167. cpvw_get("cooliris_rightclick").appendChild(_25);
  168. }
  169. }
  170. _25=document.createElement("menuitem");
  171. _25.setAttribute("label","Disable this feature");
  172. _25.setAttribute("value",i);
  173. _25.setAttribute("class","menuitem-iconic");
  174. _25.addEventListener("command",function(evt){
  175. _23.isShowingMenu=false;
  176. cpvw_prefHandler.setPref(cpvw_Prefs.prefInlineSubsearch,false);
  177. setTimeout(function(){
  178. cpvw_Prefs.showStatusMenu();
  179. },100);
  180. var _2a=cpvw_get("cooliris_status_menu");
  181. setTimeout(function(){
  182. _2a.hidePopup();
  183. },4000);
  184. },false);
  185. cpvw_get("cooliris_rightclick").appendChild(_25);
  186. _25=document.createElement("menuitem");
  187. _25.setAttribute("label","Add more >>");
  188. _25.setAttribute("value",i);
  189. _25.setAttribute("class","menuitem-iconic");
  190. _25.addEventListener("command",function(evt){
  191. _23.isShowingMenu=false;
  192. cpvw_Prefs.showPrefDialog(evt,true);
  193. },false);
  194. cpvw_get("cooliris_rightclick").appendChild(_25);
  195. this.isShowingMenu=true;
  196. },removeIcon:function(){
  197. var _2c=this;
  198. if(this.isShowingMenu){
  199. this.contextIconTimer=setTimeout(function(){
  200. _2c.removeIcon();
  201. },5000);
  202. return;
  203. }
  204. var _2d=_2c.parentDoc.getElementById("cpvw_contextIcon");
  205. if(_2d!=null){
  206. _2c.parentDoc.body.removeChild(_2d);
  207. clearTimeout(_2c.contextIconTimer);
  208. _2c.contextIconTimer=null;
  209. this.isShowingIcon=false;
  210. _2c.contextIcon=null;
  211. }else{
  212. if(_2c.contextIcon&&_2c.contextIcon.parentNode){
  213. _2c.contextIcon.parentNode.removeChild(_2c.contextIcon);
  214. _2c.contextIcon=null;
  215. }
  216. }
  217. },findNextTextNode:function(_2e,_2f,_30){
  218. var _31=_2e.createTreeWalker(_2f,NodeFilter.SHOW_TEXT,null,false);
  219. while(_31.nextNode()){
  220. if(cpvw_jsUtils.trimWhitespace(_31.currentNode.nodeValue)!=""&&_30!=_31.currentNode){
  221. return _31.currentNode;
  222. }
  223. }
  224. }};
  225. function cpvw_fireEvent(_32,_33,_34,doc){
  226. if(doc==null){
  227. doc=document;
  228. }
  229. var evt=doc.createEvent("Events");
  230. evt.initEvent(_32,true,true);
  231. for(var _37 in _34){
  232. evt[_37]=_34[_37];
  233. }
  234. _33.dispatchEvent(evt);
  235. }
  236.  
  237.